<%--
  Created by IntelliJ IDEA.
  User: 任
  Date: 2020/1/17
  Time: 14:11
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html  class="x-admin-sm">
<head>
    <title>后台登录-X-admin2.2</title>
    <link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
    <script type="text/javascript" src="/static/jquery/jquery-2.1.1.min.js"></script>
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>


    <title>登陆页面</title>
    <link href="/static/css/bootstrap-progressbar-3.3.4.min.css" rel="stylesheet" type="text/css">

    <script type="text/javascript">
        var id;//定时器的id,停止定时器时需要
        var count=60;//倒计时的时间,单位是秒
        $(function () {
            $("#sendCode").click(function(){
                //获取手机号
                var phone=$("#phone").val();
                if(phone.length==0){
                    alert("手机号不能为空!");
                    return;
                }
                //禁用按钮
                $(this).attr("disabled","disabled");
                //启动倒计时
                id=setInterval("time()",1000);
                //发送ajax
                $.getJSON("/user/sendCode.do",{phone:phone},function(result){
                    if(result.msg("OK")){
                        alert("验证码已发出!");
                    }else {
                        alert(result.msg);
                    }
                })
            })

            $("#btnLogin").click(function(){
                var  code=$("#code").val();
                $.getJSON("/user/login.do",{code:code},function (result) {
                    if(result.msg=="ok"){
                        location.href="/jsp/success_login.jsp";
                    }else{
                        alert(result.msg);
                    }
                })
            })

        });

        function time(){
            //剩余时间
            count--;
            if(count==0){
                //取消禁用
                $("#sendCode").removeAttr("disabled");
                //恢复60s
                count=60;
                $("#sendCode").val("重新发送");
                clearInterval(id);
            }else{
                //修改按钮文字
                $("#sendCode").val(count+"s后,重新发送");
            }
        }


        $(function () {
            $("#phone").blur(function () {
                var phone=$("#phone").val();
                $.getJSON("/user/id",{user:user},function (data) {
                    //可用
                    if(data.user=="no"){
                        /*  $("#span").html("不可用").css("color","red");*/
                        alert("不可用");
                    }else{

                    }
                })
            })
        })

        $(function () {
            var password=$("#userpassword").val();
            if(password<=6){
                $("#msg").html("密码不能小于6位!!");
                return false;
            }
            if(password==""){
                $("#msg").html("密码不能为空!!");
                return false;
            }
        })
    </script>
    <script>
        /*function userId() {
            var phone=$("#phone").val();
            $.ajax({
                url:"/user/id",
                type:"post",
                data:{"phone":phone},
                dataType:"JSON",
                success:function (data) {
                    if(data.user=="yes"){
                        alert("手机号已经存在");
                        return ;
                    }
                }
            })

        }*/


    </script>
    <link rel="stylesheet" href="/static/css/denglumoban/css/reg.css">
    <link rel="stylesheet" href="/static/css/denglumoban/css/base.css">
</head>
<body>

<div class="container" style="margin-top: 50px;z-index: 1">
    <form class="form-signin" action="/user/Add/user">


        <h2 class="form-signin-heading">手机注册</h2>
        <input onblur="userId()" type="text" class="form-control" id="phone" name="phone" placeholder="手机号" required="" autofocus=""/>
        <span id="span"></span><br>
        <input type="code" class="form-control" name="code" placeholder="验证码" required="" autofocus=""/>
        <input type="button" class="form-control" id="sendCode" value="发送验证码"><br>
        <input type="password" class="form-control" id="userpassword" name="userpassword" placeholder="密码" required=""/><br>
        <span>${msg}</span>
        <button class="btn btn-lg btn-primary btn-block" type="submit">注册</button>
        <button class="btn btn-lg btn-primary btn-block"  onclick="history.go(-1)">返回</button>
    </form>
</div>
</body>
</html>